<template>
  <view>
    <view>
      age：{{age}}
    </view>
    <view>
      <button @click="updateAge">updateAge</button>
    </view>
    <view>
      username：{{username}}
    </view>
    <view>
      <button @click="updateUsername">updateUsername</button>
    </view>
    <view>
      <button @click="update">update</button>
    </view>
    <view>
      <button @click="update2">对象方式</button>
    </view>
  </view>
</template>

<script lang="ts">
import Vue from 'vue'
import {NumberUtils} from 'great-jsutils'

export default Vue.extend({
  methods: {
    updateAge(){
      this.$store.commit("updateAge");
    },
    updateUsername(){
      this.$store.commit("updateUsername", 'user'+NumberUtils.randomInt());
    },
    update2(){
      this.$store.commit({
        type:'update',
        username:'user'+NumberUtils.randomInt()
      });
    },
    update(){
      this.$store.commit(
          "update",
          {
            username:'user'+NumberUtils.randomInt(),
            age: NumberUtils.randomInt({max:100})
          });
    }
  },
  computed: {
    age(){
      return this.$store.state.age
    },
    username(){
      return this.$store.state.username
    }
  }
})
</script>

<style scoped>

</style>
